import {
	validatenull
} from '@/utils/validate'
/**
 * 存储localStorage
 */
export const setStore = (params = {}) => {
	let { name, content } = params
	let obj = {
		name,
		content,
		dataType: Object.prototype.toString.call(content)
	}
	uni.setStorageSync(name, JSON.stringify(obj))
}

/**
 * 获取localStorage
 */
export const getStore = (name) => {
	let obj = uni.getStorageSync(name)
	if(obj){
		obj = JSON.parse(obj)
		if (obj.dataType === '[object Number]') {
		    return Number(obj.content)
		}
		if (obj.dataType === '[object Boolean]') {
		    return eval(obj.content)
		}
		return obj.content
	}
	return ''
}

/**
 * 删除localStorage
 */

export const removeStore = (name) => {
	uni.removeStorageSync(name)
}

/**
 * 清空全部localStorage
 */
export const clearStore = (params = {}) => {
	uni.clearStorageSync()
}
